package cn.qingyun.gis.modules.express.controller;

import cn.qingyun.gis.common.Result;
import cn.qingyun.gis.modules.express.service.IExpressDataInitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/data/init")
@Api(value = "数据初始化", tags = {"数据初始化"})
public class DataInitController {
    @Resource
    private IExpressDataInitService iExpressDataInitService;

    @ApiOperation(value = "初始化垂类地址信息匹配结果表.xlsx")
    @PostMapping("/initExpressExcel20230727")
    public Result<?> initExpressExcel20230727(@RequestParam("file") MultipartFile file) {
        iExpressDataInitService.initExpressExcel20230727(file);
        return Result.okData("正在初始化垂类地址（快递）信息匹配数据, 请稍后");
    }

    @ApiOperation(value = "导入垂类地址信息匹配结果表.xlsx")
    @PostMapping("/importExpressExcel20230727")
    public Result<?> importExpressExcel20230727(@RequestParam("file") MultipartFile file) {
        iExpressDataInitService.importExcel20230727(file);
        return Result.okData("正在导入垂类地址（快递）信息匹配数据, 请稍后");
    }

    @ApiOperation(value = "垂类地址信息匹配结果表0727.xlsx数据格式化")
    @GetMapping("/formatting")
    public Result<?> formattingExpressExcel() {
        iExpressDataInitService.formattingExpressExcel();
        return Result.ok("格式化成功");
    }

    @ApiOperation(value = "导出垂类地址信息匹配结果表0727.xlsx")
    @GetMapping("/exportExpressExcel20230727")
    public void exportExpressExcel() {
        iExpressDataInitService.exportExpressExcel();
    }

    @ApiOperation(value = "导出垂类地址信息数据(主表+附表)")
    @GetMapping("/exportExpressProofreadExcel")
    public void exportExpressProofreadExcel() {
        iExpressDataInitService.exportExpressProofreadExcel();
    }

    @ApiOperation(value = "导出垂类地址全量明细数据")
    @GetMapping("/exportExpressDetail")
    public void exportExpressDetail(HttpServletRequest request) {
        iExpressDataInitService.exportExpressDetail(request);
    }

    @ApiOperation(value = "初始化business_grid.csv")
    @PostMapping("/importBusinessGridCsv")
    public Result<?> importBusinessGridCsv(@RequestParam("file") MultipartFile file) {
        iExpressDataInitService.importBusinessGridCsv(file);
        return Result.okData("正在导入business_grid.csv, 请稍后");
    }

    @ApiOperation(value = "导出business_grid.csv")
    @GetMapping("/downloadRegionCsv")
    public void downloadRegionCsv() {
        iExpressDataInitService.downloadRegionCsv();
    }

    @ApiOperation(value = "格式化business_grid.csv")
    @GetMapping("/formattingBusinessGridCsv")
    public Result<?> formattingBusinessGridCsv() {
        iExpressDataInitService.formattingBusinessGridCsv();
        return Result.okData("正在格式化business_grid.csv, 请稍后");
    }

    @ApiOperation(value = "初始化grid_new.csv")
    @PostMapping("/importGridNewCsv")
    public Result<?> importGridNewCsv(@RequestParam("file") MultipartFile file) {
        iExpressDataInitService.importGridNewCsv(file);
        return Result.okData("正在导入grid_new.csv, 请稍后");
    }


    @ApiOperation(value = "格式化grid_new.csv")
    @GetMapping("/formattingGridNewCsv")
    public Result<?> formattingGridNewCsv() {
        iExpressDataInitService.formattingGridNewCsv();
        return Result.okData("正在格式化grid_new.csv, 请稍后");
    }

    @ApiOperation(value = "垂类地址信息匹配结果表0727（处理）.xlsx导入")
    @PostMapping("/importHandleExpressExcel20230727")
    public Result<?> importHandleExpressExcel20230727(@RequestParam("file") MultipartFile file) {
        iExpressDataInitService.importHandleExpressExcel20230727(file);
        return Result.okData("正在导入垂类地址信息匹配结果表0727（处理）, 请稍后");
    }

    @ApiOperation(value = "垂类地址信息匹配结果表0727.xlsx数据（处理）格式化")
    @GetMapping("/formattingHandleExpressExcel")
    public Result<?> formattingHandleExpressExcel() {
        iExpressDataInitService.formattingHandleExpressExcel();
        return Result.ok("垂类地址信息匹配结果表0727.xlsx数据格式化成功");
    }

    @ApiOperation(value = "垂类地址信息匹配结果表0727.xlsx数据（处理）导出")
    @GetMapping("/exportHandleExpressExcel")
    public void exportHandleExpressExcel(HttpServletResponse response) {
        iExpressDataInitService.exportHandleExpressExcel(response);
    }

}
